<template>
	<view class="content">
		<view class="wid100 dis disAl disJuC" style="height: 100rpx;background: #E5EEFF;">
			<picker class="wid90" mode="date" fields="month" :end="end" :value="date" @change="bindDateChange">
				<view class="dis disAl">
					<view class="fowe600" style="color: black;">{{date}}</view>
					<view class="mar-left20 dis disAl foSi20 " style="color: #6C717A;">切换
					<uni-icons type="right" size="20rpx"></uni-icons></view>
				</view>
			</picker>
		</view>
		<scroll-view style="height: calc(100vh - 100rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view style="height: 1rpx;"></view>
			<block v-for="(item,index) in list" :key="index">
				<view class="wid100 bacFFF mar-top30" style="padding: 40rpx 0;">
					<view class="wid90 mar">
						<view class="dis disAl disJuB ">
							<view class="foSi35 fowe600">充值成功</view>
							<view class="foSi40 fowe600" style="color: #035DFF;">+{{item.money}}</view>
						</view>
						<view class="dis disAl disJuB foSi25 mar-top30" style="color: #5B5B5B;">
							<view>{{dateFormat1(item.createtime)}}</view>
							<view>余额：¥{{item.remain}}</view>
						</view>
					</view>
				</view>
				<view class="wid100 xia"></view>
			</block>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				list: [],
				last_page: 0,
				page: 1,
				date: '',
				end: new Date()
			}
		},
		onLoad() {
			this.date = this.dateFormat()
			this.getList()
		},
		onShow() {},
		methods: {
			dateFormat1(time) {
				let date = new Date(time*1000);
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year + "-" + month + "-" + day+ " " + hours + ":" + minutes + ":" + seconds;
			},
			dateFormat() {
				let date = new Date();
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				return year+"-"+month;
				// return year + "-" + month + "-" + day;
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
				this.page = 1
				this.getList()
			},
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_recharge_order_lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						page: that.page,
						limit: 10,
						status: 1,
						month: that.date
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.last_page = result.data.last_page
							if(that.page == 1){
								that.list = result.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
		}
	}
</script>

<style>
	.content {}
	.xia{
		height: 1rpx;
		background: #D2D2D2;
	}
</style>
